//
//  WHCLPlayVC.swift
//  Tinsecret_TW
//
//  Created by wanghui on 2019/3/12.
//  Copyright © 2019年 tst. All rights reserved.
//

import UIKit

class WHCLPlayerVC: ChatBaseController {
    
    var playerView: CLPlayerView?
    var url: URL?
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isHidden = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.navigationController?.navigationBar.isHidden = false
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        self.playerView?.destroyPlayer()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        self.playerView = CLPlayerView.init(frame: CGRect.init(x: 0, y: 0, width: kScreenW, height: kScreenH))
        self.view.addSubview(self.playerView!)
        self.playerView?.update(config: { (config) in
            //是否重复播放?
            config?.repeatPlay = false
            //当前控制器是否支持旋转，当前页面支持旋转的时候需要设置，告知播放器
            config?.isLandscape = true
            //全屏状态栏 跟随工具栏, 工具栏隐藏就隐藏, 工具栏不隐藏就不隐藏
            config?.fullStatusBarHiddenType = FullStatusBarHiddenType.followToolBar
            //顶部工具条隐藏样式, 一直不隐藏
            config?.topToolBarHiddenType = TopToolBarHiddenType.never

        })
        //视频地址
        self.playerView?.url = url!
        //播放
        self.playerView?.playVideo()
        self.playerView?.backButton({ (btn) in
            self.navigationController?.popViewController(animated: true)
        })
        //播放完成回调
        self.playerView?.endPlay({
            print("播放完成")
        })
        
    }
    
    // 隐藏状态栏
    override var prefersStatusBarHidden: Bool {
        get {
            return true
        }
    }
}


extension WHCLPlayerVC {
    //pragma mark -- 需要设置全局支持旋转方向，然后重写下面三个方法可以让当前页面支持多个方向
    func shouldAutorotate() -> Bool {
        return false
    }
    
    func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.portrait
    }
    
    func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
        return UIInterfaceOrientation.portrait
    }
}

